﻿using Expression.Blend.SampleData.SampleDataSource;
using System;
using System.Collections.Generic;
using Windows.ApplicationModel.Activation;
using Windows.UI.Xaml;
using Windows.UI.Core;
using Windows.UI.Popups;
using Twilio;

namespace RobertMcLaws.TwilioForWin8
{
    partial class App
    {
        // TODO: Create a data model appropriate for your problem domain to replace the sample data
        public static TwilioDataSource SampleData;

        public static TwilioRestClient TwilioClient;

        public App()
        {
            InitializeComponent();
        }

        protected override void OnLaunched(LaunchActivatedEventArgs args)
        {
            //ShowGroupedCollection();
            Window.Current.Content = new MainPage();
            Window.Current.Activate();
        }

        public static void ShowGroupedCollection()
        {
            //CheckCredentials();
            var page = new GroupedCollectionPage();
            if (SampleData == null) SampleData = new TwilioDataSource(page.BaseUri);
            page.Groups = SampleData.GroupedCollections;
            Window.Current.Content = page;
        }

        public static void ShowCollectionSummary(IEnumerable<object> collection)
        {
            var page = new CollectionSummaryPage();
            if (SampleData == null) SampleData = new TwilioDataSource(page.BaseUri);
            page.Items = collection;
            page.Item = collection;
            Window.Current.Content = page;
        }

        public static void ShowDetail(IEnumerable<object> collection, object item)
        {
            var page = new DetailPage();
            if (SampleData == null) SampleData = new TwilioDataSource(page.BaseUri);
            page.Items = collection;
            page.Item = item;
            Window.Current.Content = page;
        }

        public static void CheckCredentials()
        {
            if (string.IsNullOrWhiteSpace(AppSettings.AccountSidSetting))
            {
                var flyout = new Windows.UI.Popups.MessageDialog("test", "test");
                flyout.Commands.Add(new UICommand("OK!", null));
                flyout.ShowAsync().Start();
            }
        }

    }
}
